<template>
  <div>
    <chart-type-view @sendTypeChange="typeChange"></chart-type-view>
    <loading-view :data="chartData">
      <div>
        <count-chart :type="1" :count-list="countData.learnCountList" @sendMoreClick="countMoreClick"></count-chart>
        <test-chart :count-list="countData.testCountList"></test-chart>
        <funnel-chart :count-list="countData.funnelCountList"></funnel-chart>
        <course-chart :type="1" :count-list="countData.courseCountList" @sendMoreClick="courseMoreClick"></course-chart>
        <cert-chart :type="1" :count-list="countData.certCountList" @sendMoreClick="certMoreClick"></cert-chart>
      </div>
    </loading-view>
  </div>
</template>


<script>

  import UniversityTool from '@/pages/university/UniversityTool'
  import CountChart from './components/CountChart'
  import TestChart from './components/TestChart'
  import CourseChart from './components/CourseChart'
  import CertChart from './components/CertChart'
  import LoadingView from '@/components/LoadingView'
  import FunnelChart from "./components/FunnelChart";
  import ChartTypeView from "./components/ChartTypeView";
  import {Toast} from 'vant'

  export default {
    name: "chart-total",
    data() {
      return {
        chartData: {},
        type: 0,
      }
    },
    components: {
      ChartTypeView,
      FunnelChart,
      CountChart,
      TestChart,
      CourseChart,
      CertChart,
      LoadingView
    },
    mounted() {
      this.getChartData()
    },
    computed: {
      countData() {
        return this.chartData
      },
    },
    methods: {
      typeChange(e) {
        this.type = e

        Toast.loading({
          duration: 0,
          message: '加载中...',
          forbidClick: true,
        });

        this.getChartData()
      },
      countMoreClick() {
        let teamId = this.$store.getters.enterpriseInfo.enterprise.id;
        //成员统计   非门店统计
        if(this.type == 0){
          this.$_router.push(`/learnValueCharts/${teamId}/1`)
        }else if(this.type == 1){
          this.$_router.push(`/learnValueChartsTeam/${teamId}`)
           //统计门店数据入口
        }


      },
      courseMoreClick() {
        let teamId = this.$store.getters.enterpriseInfo.enterprise.id;
        //成员统计   非门店统计
        if(this.type == 0){
          this.$_router.push(`/courseCharts/${teamId}/1`)
        }else if(this.type == 1){
          this.$_router.push(`/courseChartsTeam/${teamId}`)
          //统计门店数据入口
        }
      },
      certMoreClick()  {
        let teamId = this.$store.getters.enterpriseInfo.enterprise.id;
        //成员统计   非门店统计
        if(this.type == 0){
          this.$_router.push(`/certCharts/${teamId}/1`)
        }else if(this.type == 1){
          this.$_router.push(`/certChartsTeam/${teamId}`)
          //统计门店数据入口
        }
      },
      getChartData() {
        let teamId = this.$store.getters.enterpriseInfo.enterprise.id;

        if (this.type == 0) {
          UniversityTool.getSummaryChartUserData(teamId).then((chart) => {
            this.chartData = chart
          }).finally(() => {
            Toast.clear()
          })
        } else {
          UniversityTool.getSummaryChartTeamData(teamId).then((chart) => {
            this.chartData = chart
          }).finally(() => {
            Toast.clear()
          })
        }

      }

    }

  }
</script>

<style scoped>

</style>
